package com.oba.king.datalib;

import java.util.ArrayList;
import java.util.List;

import javax.faces.model.SelectItem;

import com.oba.base.dao.DBDataModel;
import com.oba.base.service.BaseBean;

/**
 * 
 * @author 大饼
 * 收货人信息管理
 */
public class RecieverInfoBean extends
		BaseBean<RecieverInfo, RecieverInfoService> {

	private DBDataModel recieverInfoData = DBDataModel.create();
	private RecieverInfo recieverInfo;
	// 查询条件对象
	private RecieverCondition recieverCondition;
	// 查询时公司列表
	private List<SelectItem> queryCustomerList;
	// 是否弹出弹出层
	private boolean showRecieverInfo = false;
	private List<SelectItem> customerList;

	@Override
	public String doFind() {
		recieverInfoData.find(this.getService().getDao().findAll());
		return null;
	}
     
	public void findByReciever(){
		
			recieverInfoData.find(getService().getDao().findByReciever(recieverCondition));
		
	}

	public void doAddRow() {
		
  		recieverInfo = new RecieverInfo();
  		recieverInfo.setNewBo(true);
  		showRecieverInfo = true;
	}
  	

	public void initCustomerList(){
		customerList =new ArrayList<SelectItem>();
		for(Customer a : getService().getDao().findAllCustomer()){
			customerList.add(new SelectItem(a,a.getCustomerShortName()));
		}
       }
	
	
	public void initQueryCustomerList(){
		queryCustomerList =new ArrayList<SelectItem>();
		queryCustomerList.add(new SelectItem(null,"全部"));
		queryCustomerList.addAll(customerList);
       }
	
	public void doEditRow() {
		if(recieverInfoData.isRowAvailable()) {
			recieverInfo = (RecieverInfo) recieverInfoData.getRowData();
			showRecieverInfo = true;
			doFind();
		}
	}
	
	
	public void doDeleteRow() {
		if(recieverInfoData.isRowAvailable()) {
			recieverInfo = (RecieverInfo) recieverInfoData.getRowData();
			getService().del(recieverInfo);
			doFind();
		}
	}
	
	public void closeShowEdit() {
		showRecieverInfo = false;
	}
	
	public void clearRecieverCondition(){
		recieverCondition = new RecieverCondition();
	}
	
	public void doSaveRow() {
		// TODO
		
		getService().save(recieverInfo);
		showRecieverInfo = false;
		doFind();
	}


	@Override
	public void init() {
		recieverInfoData.find(this.getService().getDao().findAll());
		recieverInfo = new RecieverInfo();
		recieverCondition=new RecieverCondition();
		initCustomerList();
		initQueryCustomerList();
		showRecieverInfo = false;
	}


	public DBDataModel getRecieverInfoData() {
		return recieverInfoData;
	}


	public void setRecieverInfoData(DBDataModel recieverInfoData) {
		this.recieverInfoData = recieverInfoData;
	}


	public RecieverInfo getRecieverInfo() {
		return recieverInfo;
	}


	public void setRecieverInfo(RecieverInfo recieverInfo) {
		this.recieverInfo = recieverInfo;
	}




	public boolean isShowRecieverInfo() {
		return showRecieverInfo;
	}


	public void setShowRecieverInfo(boolean showRecieverInfo) {
		this.showRecieverInfo = showRecieverInfo;
	}


	public List<SelectItem> getCustomerList() {
		return customerList;
	}


	public void setCustomerList(List<SelectItem> customerList) {
		this.customerList = customerList;
	}

	public RecieverCondition getRecieverCondition() {
		return recieverCondition;
	}

	public void setRecieverCondition(RecieverCondition recieverCondition) {
		this.recieverCondition = recieverCondition;
	}

	public List<SelectItem> getQueryCustomerList() {
		return queryCustomerList;
	}

	public void setQueryCustomerList(List<SelectItem> queryCustomerList) {
		this.queryCustomerList = queryCustomerList;
	}


}
